﻿@model IMS_Partner
@{
	ViewBag.Title = (Model.ID > 0 ? "修改" : "新增") + "客户";
}
@section header {
	@*<link href="~/lib/select2/select2.min.css" rel="stylesheet" asp-append-version="true" />*@
	<style>
		.detail-content-info, .detail-content-label {
			padding: 3px;
		}
	</style>
}
@section quickmenu {
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="返回..." @@click="pageBack">
			<i class="icon-reply icon-2x pull-left icon-border crm-bu-style"></i>
		</span>
	</td>
}

<table style="border:0;margin:0;border-spacing:0;width:100%;padding:0 15px 10px 15px;overflow:auto;table-layout:fixed;">
	<tbody>
		<tr>
			<td class="detail-left-td">
				<div class="detail-panel-div">
					<div class="detail-inner">
						<div class="detail-name-div" title="@(Model.ID>0?Model.Name:"客户")">
							@(Model.ID > 0 ? Model.Name : "客户")
						</div>
					</div>
					<div class="detail-heading">
						相关记录
					</div>
					<div class="detail-inner detail-related">
						<div class="detail-list-div-disabled" v-for="(ritem) in related">
							{{ritem.name}}
						</div>
					</div>
					<div class="detail-exit">&nbsp;</div>
				</div>
			</td>
			<td style="vertical-align:top;" class="detail-content-td">
				<div style="width:100%;margin:0;padding:0;" v-show="viewid=='main'">
					<table style="width:100%;">
						<tr>
							<td style="vertical-align:top;">
								<form id="frmEdit">
									<div class="detail-panel-div" style="position:relative;">
										<table border="0" cellspacing="0" cellpadding="5" style="height:42px;width:100%;">
											<tbody>
												<tr class="detail-content-heading" style="height: 28px;">
													<td colspan="2">
														<b>&nbsp;基本信息&nbsp;</b>
													</td>
												</tr>
												<tr>
													<td colspan="2">
														<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
															<tr style="height: 25px">
																<td class="detail-content-label label-required">
																	类型
																</td>
																<td class="detail-content-info" colspan="3">
																	<input type="radio" name="Type" class="validate[required] type" v-model="model.Type" value="@((int)PartnerType.布行)" />布行
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label label-required" width="20%">
																	布行名
																</td>
																<td class="detail-content-info" width="30%">
																	<input type="text" class="detailedViewTextBox validate[required]" v-model.trim="model.Name" @@change="handleChangeName">
																</td>
																<td class="detail-content-label" width="20%">
																	拼音助记码
																</td>
																<td class="detail-content-info" width="30%">
																	<input type="text" class="detailedViewTextBox input-sm" v-model.trim="model.PYCode" @@change="handleChangePYCode">
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	往来单位编码
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model.trim="model.Code">
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	电话
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model.trim="model.Phone" />
																</td>
																<td class="detail-content-label">
																	传真
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model="model.Fax" />
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	联系人
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model="model.ContactMan" />
																</td>
																<td class="detail-content-label">
																	联系电话
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model.trim="model.ContactPhone" />
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	详细地址
																</td>
																<td class="detail-content-info distpicker" colspan="3">
																	<select class=""></select>
																	<select class=""></select>
																	<select class=""></select>
																	@*<select v-model="model.Town"></select>*@
																	<input type="text" class="detailedViewTextBox" v-model="model.Location" style="width:30%;vertical-align: top;margin-top: 2px">
																</td>
															</tr>
															<tr>
																<td class="detail-content-label">
																	备注
																</td>
																<td class="detail-content-info" colspan="3">
																	<textarea v-model="model.Comment" style="height:35px;"></textarea>
															</tr>
														</table>
													</td>
												</tr>
												<tr style="height: 38px;">
													<td style="text-align:center;">
														<button class="pure-button pure-button-edit" onclick="$('#frmEdit').submit();return false;" style="margin-right:50px;">
															<i class="icon-check"></i>&nbsp;保存&nbsp;
														</button>
														<button class="pure-button" @@click.prevent='pageBack'>
															<i class="icon-undo"></i>&nbsp;取消&nbsp;
														</button>
													</td>
												</tr>
											</tbody>
										</table>
									</div>
								</form>
							</td>
							<td class="detail-right-td" style="">
								<div class="detail-panel-div">
									<div class="detail-inner">
										<table border="0" cellpadding="5" cellspacing="0" class="module-tool-tab" style="width:100%;">
											<tr>
												<td align="left" class="genHeaderSmall" style="padding:5px;">操作</td>
											</tr>
											<tr>
												<td align="left" style="padding:5px;">
													<img src="~/theme/img/pointer.gif" hspace="5" />
													<a href="javascript:viewDetailLog(@((int)ST.Buz.Base.Enums.TableCode.IMS_Partner),@(Model.ID));" class="webMnu">修改日志</a>
												</td>
											</tr>
										</table>
									</div>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</td>
		</tr>
	</tbody>
</table>
@section footer {
	<script src="~/js/related/sys_attachment.js" asp-append-version="true"></script>
	<script src="~/js/pinyin.js" asp-append-version="true"></script>
	@*日期必须开始*@
	@*<script src="~/lib/laydate/laydate.js" asp-append-version="true"></script>*@
	@*日期必须结束*@
	<script src="~/lib/distpicker.js" asp-append-version="true"></script>
	@*<script src="~/lib/select2/select2.min.js" asp-append-version="true"></script>*@
	@*验证开始*@
	<script src="~/lib/validationEngine/jquery.validationEngine.min.js" asp-append-version="true"></script>
	<script src="~/lib/validationEngine/jquery.validationEngine-zh_CN.js" asp-append-version="true"></script>
	<link href="~/lib/validationEngine/validationEngine.jquery.css" rel="stylesheet" asp-append-version="true" />
	@*验证结束*@
	@*列表相关开始*@
	<script type="text/javascript">
		var pageEnumData = {
			state:@(Json.Serialize(ViewBag.StateOptions)),
		};
		var modelJson=@(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model, new Newtonsoft.Json.JsonSerializerSettings()
		   {
			   DateFormatString = "yyyy-MM-dd HH:mm:ss"
		   })));
		var modelData = $.extend(modelJson, {
		});
		var pageData = {
			hideBreadcrumb:false,
			serviceCode: '@(ViewBag.ServiceCode)',
			global: globalData,
			viewid: 'main',
			related: @(Json.Serialize(ViewBag.RelatedModules)),
			model:modelData
		};

		var pageApp = new Vue({
			el: '#app',
			data: pageData,
			created: function () {
			},
			mounted: function () {
			},
			methods: {
				pageBack: function () {
					//history.go(-1);
					if (@(Model.ID > 0 ? "true" : "false")) {
						history.back();
					} else {
						location.href = '@(Url.Action("List", "Partner"))?nc=' + new Date().getTime();
					}
				},
				pageSave: function () {
					utils.ajaxPost('@(Url.Action("Save", "Partner"))', this.model, function (resp) {
						console.log(resp.data);
						utils.success("保存成功");
						location.href = '@(Url.Action("ViewDetail", "Partner", new { id = "" }))/'+resp.data+'?nc=' + new Date().getTime();
					}, function (msg) {
						utils.alert(msg);
					});
				},
				handleChangeName: function () {
					var _this=this;
					_this.model = Object.assign({}, _this.model, {
						PYCode: utils.pinyin.getFirstLetter(_this.model.Name).substr(0, 10),
					});
				},
				handleChangePYCode: function () {
					var _this = this;
					if (!!_this.model.PYCode) {
						_this.model.PYCode = _this.model.PYCode.toUpperCase().substr(0, 10);
					}
				},
				relatedSysAttachmentChange: function (vid, e) {
					switch (e.action) {
						case "total":
							{
								this.related = this.related.map(function (item) {
									if (item.id == vid) {
										return Object.assign({}, item, { count: e.data });
									} else {
										return item;
									}
								});
							}
							break;
					}
				},
				changeView: function (vid) {
					this.viewid = vid;
					this.$refs[vid]&&this.$refs[vid].reload();
				},
				resetView: function () {
					this.viewid = 'main';
				}
			},
			computed: {
				currentM: function () {
					var currentM = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentM = this.global.modules[i];
								break;
							}
						}
					}
					return currentM;
				},
				currentS: function () {
					var currentS = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentS = this.global.modules[i].Services[j];
								break;
							}
						}
					}
					return currentS;
				}
			}
		});

		$(document).ready(function () {
			$("#frmEdit").keypress(function (e) {
				if (e.keyCode == 13) {
					return false;
				}
			}).validationEngine({
				scroll: false,
				validateNonVisibleFields: false,
				autoHidePrompt: true,
				showOneMessage: true,
				ajaxFormValidationMethod: 'post',
				custom_error_messages: {
					 '.type': {
						'required': {
							'message': '类型不能为空'
						}
					}
				},
				onValidationComplete: function (form, status) {
					if (!status) {
						return;
					}
					var $districts = $(".distpicker select");
					modelData.Province = $districts[0].value;
					modelData.City = $districts[1].value;
					modelData.District = $districts[2].value;
					pageApp.pageSave();
				}
			});

			$(".distpicker").distpicker({
				province: modelData.Province || '',
				city: modelData.City || '',
				district: modelData.District || ''
			});
		});

		// function openCat() {
		// 	utils.layerPop('@(Url.Action("PopList", "Sys_EnumCode"))?id=@(ViewBag.PartnerCatEnumID)&callback=popPartnerCatCallback', '400px', '450px', '#CatID')
		// }

		// function popPartnerCatCallback(popIndex,ret) {
		// 	if (!ret || ret.id == '' || ret.id == '0' || ret.id == '-1') {
		// 		return;
		// 	}
		// 	pageApp.model = Object.assign({}, pageApp.model, {
		// 		CatID: ret.id,
		// 		CatName: ret.LevelName || ret.Name,
		// 	});
		// 	layer.close(popIndex);
		// }

		// function clearCat() {
		// 	pageApp.model = Object.assign({}, pageApp.model, {
		// 		CatID: 0,
		// 		CatName: "",
		// 	});
		// }
	</script>
	@*列表相关结束*@
}